﻿namespace Fiddler
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Text.RegularExpressions;
    using System.Threading;
    using System.Windows.Forms;

    public class SessionListView : ListView
    {
        internal string[] _emptyBoundColumns = new string[0];
        private Point _ptContextHeaderPopup;
        private int _uiAsyncUpdateInterval;
        private static Dictionary<string, BoundColumnEntry> dictBoundColumns = new Dictionary<string, BoundColumnEntry>();
        public SimpleEventHandler OnSessionsAdded;
        private List<ListViewItem> qLVIsToAdd;
        private System.Windows.Forms.Timer timer_LVIAddQueue;
        private WeakReference wrCurrentItem;
        private WeakReference wrPriorItem;

        [Description("Fired when the user hits ALT+Enter with a single item selected")]
        public event EventHandler ItemShowProperties;

        public SessionListView()
        {
            if (!base.DesignMode)
            {
                this.DoubleBuffered = true;
                base.FontChanged += new EventHandler(this.SessionListView_FontChanged);
            }
            base.ListViewItemSorter = new ListViewItemComparer(this);
            base.ColumnClick += new ColumnClickEventHandler(this.OnColumnClick);
            base.MouseDown += new MouseEventHandler(this.SessionListView_MouseDown);
        }

        private void _DoSearchColumns(int iCol, bool bNumeric, string sWhatFor)
        {
            if (bNumeric)
            {
                SearchNumericColumn(iCol, sWhatFor);
            }
            else
            {
                SearchTextColumn(iCol, sWhatFor);
            }
            if (this.SelectedCount > 0)
            {
                if (base.SelectedIndices.Count > 0)
                {
                    base.EnsureVisible(base.SelectedIndices[0]);
                }
                base.Focus();
            }
            else
            {
                FiddlerApplication.UI.sbpInfo.Text = "No Web Sessions matched your query.";
            }
        }

        internal void ActivatePreviousItem()
        {
            if (this.wrPriorItem != null)
            {
                ListViewItem target = this.wrPriorItem.Target as ListViewItem;
                if (target != null)
                {
                    base.SelectedItems.Clear();
                    target.Selected = true;
                    target.Focused = true;
                }
            }
        }

        public bool AddBoundColumn(string sColumnTitle, int iWidth, getColumnStringDelegate delFn)
        {
            return (((sColumnTitle != null) && (delFn != null)) && this.AddBoundColumn(sColumnTitle, -1, iWidth, null, false, delFn));
        }

        [CodeDescription("Add a bound column with the specified title & width, displaying the specified FlagName")]
        public bool AddBoundColumn(string sColumnTitle, int iWidth, string sSessionFlagName)
        {
            return this.AddBoundColumn(sColumnTitle, -1, iWidth, sSessionFlagName);
        }

        [CodeDescription("Add a bound column with the specified title, relative order, and width, with value bound to the result of the specified getColumnStringDelegate function.")]
        public bool AddBoundColumn(string sColumnTitle, int iRelativeOrder, int iWidth, getColumnStringDelegate delFn)
        {
            return (((sColumnTitle != null) && (delFn != null)) && this.AddBoundColumn(sColumnTitle, iRelativeOrder, iWidth, null, false, delFn));
        }

        [CodeDescription("Add a bound column with the specified title, relative order, and width, displaying the specified FlagName")]
        public bool AddBoundColumn(string sColumnTitle, int iRelativeOrder, int iWidth, string sSessionFlagName)
        {
            getColumnStringDelegate delFn = null;
            getColumnStringDelegate delegate3 = null;
            if ((sColumnTitle == null) || (sSessionFlagName == null))
            {
                return false;
            }
            if (sSessionFlagName.StartsWith("@request.", StringComparison.OrdinalIgnoreCase))
            {
                if (delFn == null)
                {
                    delFn = delegate(Session oSession)
                    {
                        if (((oSession != null) && (oSession.oRequest != null)) && (oSession.oRequest.headers != null))
                        {
                            return oSession.oRequest.headers[sSessionFlagName.Substring(9)];
                        }
                        return string.Empty;
                    };
                }
                return this.AddBoundColumn(sColumnTitle, iRelativeOrder, iWidth, null, false, delFn);
            }
            if (!sSessionFlagName.StartsWith("@response.", StringComparison.OrdinalIgnoreCase))
            {
                return this.AddBoundColumn(sColumnTitle, iRelativeOrder, iWidth, sSessionFlagName, false, null);
            }
            if (delegate3 == null)
            {
                delegate3 = delegate(Session oSession)
                {
                    if (((oSession != null) && (oSession.oResponse != null)) && (oSession.oResponse.headers != null))
                    {
                        return oSession.oResponse.headers[sSessionFlagName.Substring(10)];
                    }
                    return string.Empty;
                };
            }
            return this.AddBoundColumn(sColumnTitle, iRelativeOrder, iWidth, null, false, delegate3);
        }

        [CodeDescription("Add a bound column with the specified title, relative order, and width, with value bound to the result of the specified getColumnStringDelegate function.")]
        public bool AddBoundColumn(string sColumnTitle, int iRelativeOrder, int iWidth, bool bSortColumnNumerically, getColumnStringDelegate delFn)
        {
            return (((sColumnTitle != null) && (delFn != null)) && this.AddBoundColumn(sColumnTitle, iRelativeOrder, iWidth, null, bSortColumnNumerically, delFn));
        }

        private bool AddBoundColumn(string sColumnTitle, int iRelativeDisplayOrder, int iWidth, string sSessionFlagName, bool bSortColumnNumerically, getColumnStringDelegate delFn)
        {
            BoundColumnEntry entry;
            ColumnHeader header = null;
            if (sColumnTitle.IndexOfAny(new char[] { '~', '\x00a7' }) > -1)
            {
                sColumnTitle = sColumnTitle.Replace('~', '-').Replace('\x00a7', '$');
            }
            if (dictBoundColumns.ContainsKey(sColumnTitle))
            {
                entry = dictBoundColumns[sColumnTitle];
                entry._delFn = delFn;
                entry._sSessionFlagName = sSessionFlagName;
                if (iWidth > -1)
                {
                    header = this.FindColumnByTitle(sColumnTitle);
                    if (header != null)
                    {
                        header.Width = iWidth;
                    }
                }
                if (iRelativeDisplayOrder > -1)
                {
                    if (header == null)
                    {
                        header = this.FindColumnByTitle(sColumnTitle);
                    }
                    if (header != null)
                    {
                        header.DisplayIndex = iRelativeDisplayOrder;
                    }
                }
                return true;
            }
            header = base.Columns.Add(sColumnTitle, iWidth);
            if ((header != null) && (iRelativeDisplayOrder > -1))
            {
                header.DisplayIndex = iRelativeDisplayOrder;
            }
            int index = header.Index;
            if (delFn != null)
            {
                entry = new BoundColumnEntry(delFn, index, bSortColumnNumerically);
            }
            else
            {
                entry = new BoundColumnEntry(sSessionFlagName, index, bSortColumnNumerically);
            }
            dictBoundColumns.Add(sColumnTitle, entry);
            this._emptyBoundColumns = new string[dictBoundColumns.Count];
            for (int i = 0; i < this._emptyBoundColumns.Length; i++)
            {
                this._emptyBoundColumns[i] = string.Empty;
            }
            return true;
        }

        protected override void Dispose(bool disposing)
        {
            try
            {
                if ((disposing && !base.DesignMode) && (this.timer_LVIAddQueue != null))
                {
                    this.timer_LVIAddQueue.Tick -= new EventHandler(this.timerLVIAddQueue_Tick);
                    this.timer_LVIAddQueue.Dispose();
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }

        private void DoSessionsAdded(bool bWasAtBottom)
        {
            if (CONFIG.bAutoScroll && (!CONFIG.bSmartScroll || bWasAtBottom))
            {
                int index = base.Items.Count - 1;
                if (index > -1)
                {
                    base.EnsureVisible(index);
                }
            }
            if (this.OnSessionsAdded != null)
            {
                this.OnSessionsAdded();
            }
        }

        public void EnsureItemIsVisible(ListViewItem oLVI)
        {
            if (oLVI.Index > -1)
            {
                oLVI.EnsureVisible();
            }
        }

        internal static void FillBoundColumns(Session oSession, ListViewItem oLVI)
        {
            foreach (BoundColumnEntry entry in dictBoundColumns.Values)
            {
                while (oLVI.SubItems.Count <= entry._iColNum)
                {
                    oLVI.SubItems.Add(string.Empty);
                }
                if (entry._sSessionFlagName != null)
                {
                    oLVI.SubItems[entry._iColNum].Text = oSession[entry._sSessionFlagName];
                }
                else
                {
                    string str = entry._delFn(oSession);
                    if (str != null)
                    {
                        oLVI.SubItems[entry._iColNum].Text = str;
                    }
                }
            }
        }

        internal ColumnHeader FindColumnByTitle(string sColumnTitle)
        {
            for (int i = 0; i < base.Columns.Count; i++)
            {
                if (string.Equals(sColumnTitle, base.Columns[i].Text, StringComparison.OrdinalIgnoreCase))
                {
                    return base.Columns[i];
                }
            }
            return null;
        }

        internal void FlushUpdates()
        {
            if ((this.qLVIsToAdd != null) && (this.qLVIsToAdd.Count > 0))
            {
                this.timerLVIAddQueue_Tick(null, null);
            }
        }

        public int GetSubItemIndexFromPoint(Point ptClient)
        {
            LVNative.LVHITTESTINFO lParam = new LVNative.LVHITTESTINFO();
            lParam.pt_x = ptClient.X;
            lParam.pt_y = ptClient.Y;
            if (-1 < ((int)LVNative.SendHitTestMessage(new HandleRef(this, base.Handle), 0x1039, IntPtr.Zero, lParam)))
            {
                return lParam.iSubItem;
            }
            return -1;
        }

        private void HeaderSearchClick(object sender, EventArgs eA)
        {
            if (this.TotalItemCount() < 1)
            {
                MessageBox.Show("No WebSessions to search", "Failed");
            }
            else
            {
                Point ptClient = base.PointToClient(this._ptContextHeaderPopup);
                ptClient.Y = base.Items[0].Bounds.Top + 1;
                int subItemIndexFromPoint = this.GetSubItemIndexFromPoint(ptClient);
                if (subItemIndexFromPoint < 0)
                {
                    MessageBox.Show("Can't find column at " + ptClient.X.ToString() + "x" + ptClient.Y.ToString(), "Sorry...");
                }
                else
                {
                    bool bNumeric = this.isColumnNumeric(subItemIndexFromPoint);
                    string sPrompt = bNumeric ? "Specify either an exact number, or > or < expression:" : "Specify either a partial string, or use the EXACT: or REGEX: prefix.";
                    string sWhatFor = frmPrompt.GetUserString("Search " + base.Columns[subItemIndexFromPoint].Text, sPrompt, string.Empty, true);
                    if (sWhatFor != null)
                    {
                        this._DoSearchColumns(subItemIndexFromPoint, bNumeric, sWhatFor);
                    }
                }
            }
        }

        private bool isColumnNumeric(int iCol)
        {
            if (iCol <= 10)
            {
                if (((iCol == 0) || (iCol == 1)) || (iCol == 5))
                {
                    return true;
                }
            }
            else
            {
                foreach (BoundColumnEntry entry in dictBoundColumns.Values)
                {
                    if (entry._iColNum == iCol)
                    {
                        return entry._bIsNumeric;
                    }
                }
            }
            return false;
        }

        public bool IsScrolledToBottom()
        {
            LVNative.SCROLLINFO structure = new LVNative.SCROLLINFO();
            structure.cbSize = (uint)Marshal.SizeOf(structure);
            structure.fMask = 7;
            if (LVNative.GetScrollInfo(base.Handle, 1, ref structure))
            {
                return ((ulong)structure.nPos >= (((ulong)structure.nMax - (ulong)structure.nPage) - ((ulong)6L)));
            }
            return true;
        }

        private void OnColumnClick(object sender, ColumnClickEventArgs e)
        {
            ((ListViewItemComparer)base.ListViewItemSorter).Column = e.Column;
            ((ListViewItemComparer)base.ListViewItemSorter).bStringCompare = !this.isColumnNumeric(e.Column) || (e.Column == 1);
            base.BeginUpdate();
            base.Sort();
            if (base.SelectedIndices.Count > 0)
            {
                base.EnsureVisible(base.SelectedIndices[0]);
            }
            base.EndUpdate();
        }

        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);
            LVNative.DontSelectBorderImage(this);
            if ((!base.DesignMode && (Environment.OSVersion.Version.Major > 5)) && FiddlerApplication.Prefs.GetBoolPref("fiddler.ui.ExplorerStyle", false))
            {
                SetWindowTheme(base.Handle, "Explorer", null);
            }
        }

        protected virtual void OnItemShowProperties(EventArgs e)
        {
            EventHandler itemShowProperties = this.ItemShowProperties;
            if (itemShowProperties != null)
            {
                itemShowProperties(this, e);
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((keyData == (Keys.Alt | Keys.Return)) && (this.SelectedCount == 1))
            {
                this.OnItemShowProperties(EventArgs.Empty);
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        internal void QueueItem(ListViewItem lvi)
        {
            if (this._uiAsyncUpdateInterval > 0)
            {
                lock (this.qLVIsToAdd)
                {
                    this.qLVIsToAdd.Add(lvi);
                    this.timer_LVIAddQueue.Enabled = true;
                    return;
                }
            }
            bool bWasAtBottom = false;
            if (CONFIG.bAutoScroll && CONFIG.bSmartScroll)
            {
                bWasAtBottom = this.IsScrolledToBottom();
            }
            base.Items.Add(lvi);
            this.DoSessionsAdded(bWasAtBottom);
        }

        internal void RemoveOrDequeue(ListViewItem lvi)
        {
            if (lvi.Index > -1)
            {
                lvi.Remove();
            }
            else
            {
                lock (this.qLVIsToAdd)
                {
                    this.qLVIsToAdd.Remove(lvi);
                }
            }
        }

        internal void SearchColumn(string sColumnName, string sFind)
        {
            int iCol = -1;
            foreach (ColumnHeader header in base.Columns)
            {
                if (string.Equals(sColumnName, header.Text, StringComparison.OrdinalIgnoreCase))
                {
                    iCol = header.Index;
                    break;
                }
            }
            if (iCol < 0)
            {
                FiddlerApplication.UI.SetStatusText(string.Format("Column '{0}' was not found.", sColumnName));
            }
            else
            {
                bool bNumeric = this.isColumnNumeric(iCol);
                this._DoSearchColumns(iCol, bNumeric, sFind);
            }
        }

        private static void SearchNumericColumn(int iCol, string sWhatFor)
        {
            if (sWhatFor.StartsWith(">"))
            {
                doesSessionMatchCriteriaDelegate oDel = null;
                double flMinValue;
                if (double.TryParse(sWhatFor.Substring(1).Replace("k", "000"), out flMinValue))
                {
                    if (oDel == null)
                    {
                        oDel = delegate(Session oS)
                        {
                            double num;
                            return (((oS.ViewItem != null) && (oS.ViewItem.SubItems.Count > iCol)) && double.TryParse(oS.ViewItem.SubItems[iCol].Text, out num)) && (num > flMinValue);
                        };
                    }
                    FiddlerApplication.UI.actSelectSessionsMatchingCriteria(oDel);
                }
            }
            else if (sWhatFor.StartsWith("<"))
            {
                doesSessionMatchCriteriaDelegate delegate3 = null;
                double flMaxValue;
                if (double.TryParse(sWhatFor.Substring(1).Replace("k", "000"), out flMaxValue))
                {
                    if (delegate3 == null)
                    {
                        delegate3 = delegate(Session oS)
                        {
                            double num;
                            return (((oS.ViewItem != null) && (oS.ViewItem.SubItems.Count > iCol)) && double.TryParse(oS.ViewItem.SubItems[iCol].Text, out num)) && (num < flMaxValue);
                        };
                    }
                    FiddlerApplication.UI.actSelectSessionsMatchingCriteria(delegate3);
                }
            }
            else
            {
                doesSessionMatchCriteriaDelegate delegate4 = null;
                double flValue;
                if (double.TryParse(sWhatFor.Replace("k", "000"), out flValue))
                {
                    if (delegate4 == null)
                    {
                        delegate4 = delegate(Session oS)
                        {
                            double num;
                            return (((oS.ViewItem != null) && (oS.ViewItem.SubItems.Count > iCol)) && double.TryParse(oS.ViewItem.SubItems[iCol].Text, out num)) && (num == flValue);
                        };
                    }
                    FiddlerApplication.UI.actSelectSessionsMatchingCriteria(delegate4);
                }
            }
        }

        private static void SearchTextColumn(int iCol, string sWhatFor)
        {
            bool bExact = false;
            Regex reSearchFor = null;
            if (sWhatFor.StartsWith("EXACT:", StringComparison.OrdinalIgnoreCase))
            {
                bExact = true;
                sWhatFor = sWhatFor.Substring(6);
            }
            else if (sWhatFor.StartsWith("REGEX:", StringComparison.OrdinalIgnoreCase))
            {
                RegexOptions options = RegexOptions.Singleline | RegexOptions.ExplicitCapture;
                try
                {
                    reSearchFor = new Regex(sWhatFor.Substring(6), options);
                }
                catch (Exception exception)
                {
                    FiddlerApplication.ReportException(exception, "Invalid Regular Expression", "Sorry, the provided regular expression could not be parsed.");
                    return;
                }
            }
            FiddlerApplication.UI.actSelectSessionsMatchingCriteria(delegate(Session oS)
            {
                if ((oS.ViewItem == null) || (oS.ViewItem.SubItems.Count <= iCol))
                {
                    return false;
                }
                if (reSearchFor != null)
                {
                    return reSearchFor.IsMatch(oS.ViewItem.SubItems[iCol].Text);
                }
                if (bExact)
                {
                    return sWhatFor.Equals(oS.ViewItem.SubItems[iCol].Text);
                }
                return -1 < oS.ViewItem.SubItems[iCol].Text.IndexOf(sWhatFor, StringComparison.OrdinalIgnoreCase);
            });
        }

        private void SessionListView_FontChanged(object sender, EventArgs e)
        {
            if (this.TotalItemCount() >= 1)
            {
                foreach (ListViewItem item in base.Items)
                {
                    if (item.Font.Size != this.Font.Size)
                    {
                        item.Font = new Font(this.Font, item.Font.Style);
                    }
                }
            }
        }

        private void SessionListView_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.XButton1)
            {
                this.ActivatePreviousItem();
            }
        }

        [CodeDescription("Set the named column's order and width. To set only one, pass -1 for the other parameter.")]
        public bool SetColumnOrderAndWidth(string sColumnTitle, int iOrder, int iWidth)
        {
            ColumnHeader header = this.FindColumnByTitle(sColumnTitle);
            if (header == null)
            {
                return false;
            }
            if (iOrder > -1)
            {
                header.DisplayIndex = iOrder;
            }
            if (iWidth > -1)
            {
                header.Width = iWidth;
            }
            this.Refresh();
            return true;
        }

        [DllImport("uxtheme.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
        public static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
        internal void StoreActiveItem()
        {
            this.wrPriorItem = this.wrCurrentItem;
            if (base.SelectedItems.Count == 1)
            {
                this.wrCurrentItem = new WeakReference(base.SelectedItems[0]);
            }
        }

        private void timerLVIAddQueue_Tick(object sender, EventArgs e)
        {
            if (!FiddlerApplication.isClosing)
            {
                ListViewItem[] itemArray;
                bool bWasAtBottom = false;
                if (CONFIG.bAutoScroll && CONFIG.bSmartScroll)
                {
                    bWasAtBottom = this.IsScrolledToBottom();
                }
                lock (this.qLVIsToAdd)
                {
                    itemArray = this.qLVIsToAdd.ToArray();
                    this.qLVIsToAdd.Clear();
                    this.timer_LVIAddQueue.Enabled = false;
                }
                if (itemArray.Length > 0)
                {
                    int iTrimTo = FiddlerApplication.Prefs.GetInt32Pref("fiddler.ui.rules.keeponly", 0);
                    if (iTrimTo > 0)
                    {
                        FiddlerApplication.UI._internalTrimSessionList(iTrimTo, false);
                    }
                    base.Items.AddRange(itemArray);
                    itemArray = null;
                    this.DoSessionsAdded(bWasAtBottom);
                }
            }
        }

        public int TotalItemCount()
        {
            int count = base.Items.Count;
            if (this.qLVIsToAdd == null)
            {
                return count;
            }
            lock (this.qLVIsToAdd)
            {
                return (count + this.qLVIsToAdd.Count);
            }
        }

        protected override void WndProc(ref Message m)
        {
            EventHandler handler = null;
            switch (m.Msg)
            {
                case 0x7b:
                    {
                        this._ptContextHeaderPopup = Cursor.Position;
                        Utilities.RECT lpRect = new Utilities.RECT();
                        IntPtr hWnd = LVNative.SendLVMessage(base.Handle, 0x101f, IntPtr.Zero, IntPtr.Zero);
                        if ((!(hWnd != IntPtr.Zero) || !Utilities.GetWindowRect(hWnd, ref lpRect)) || ((this._ptContextHeaderPopup.Y < lpRect.Top) || (this._ptContextHeaderPopup.Y > lpRect.Bottom)))
                        {
                            break;
                        }
                        if (this.ContextMenuStrip == null)
                        {
                            this.ContextMenuStrip = new ContextMenuStrip();
                            this.ContextMenuStrip.ShowImageMargin = false;
                            this.ContextMenuStrip.Items.Add("Search this column...").Click += new EventHandler(this.HeaderSearchClick);
                            if (handler == null)
                            {
                                handler = delegate(object s, EventArgs ea)
                                {
                                    try
                                    {
                                        foreach (ColumnHeader header in base.Columns)
                                        {
                                            if (header.Width < 40)
                                            {
                                                header.Width = 40;
                                            }
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                };
                            }
                            this.ContextMenuStrip.Items.Add("Ensure all columns are visible").Click += handler;
                            this.ContextMenuStrip.Items.Add("-");
                            this.ContextMenuStrip.Items.Add("Learn about configuring columns...").Click += delegate(object s, EventArgs ea)
                            {
                                Utilities.LaunchHyperlink("http://www.fiddler2.com/fiddler/help/configurecolumns.asp");
                            };
                        }
                        this.ContextMenuStrip.Items[0].Enabled = this.TotalItemCount() > 0;
                        this.ContextMenuStrip.Show(this._ptContextHeaderPopup);
                        return;
                    }
                case 0x204e:
                    {
                        LVNative.NMHDR lParam = (LVNative.NMHDR)m.GetLParam(typeof(LVNative.NMHDR));
                        if ((-187 == lParam.code) && (base.Handle == lParam.hwndFrom))
                        {
                            LVNative.NMLVEMPTYMARKUP structure = (LVNative.NMLVEMPTYMARKUP)m.GetLParam(typeof(LVNative.NMLVEMPTYMARKUP));
                            structure.szMarkup = "No Sessions captured\n(or all were hidden by filters)";
                            structure.dwFlags = 1;
                            Marshal.StructureToPtr(structure, m.LParam, false);
                            m.Result = (IntPtr)1;
                            return;
                        }
                        break;
                    }
            }
            base.WndProc(ref m);
        }

        public int SelectedCount
        {
            get
            {
                return (int)LVNative.SendLVMessage(base.Handle, 0x1032, IntPtr.Zero, IntPtr.Zero);
            }
        }

        internal int uiAsyncUpdateInterval
        {
            get
            {
                return this._uiAsyncUpdateInterval;
            }
            set
            {
                if (value < 0)
                {
                    value = 0;
                }
                if (value > 0x1388)
                {
                    value = 0x1388;
                }
                if ((value > 0) != (this._uiAsyncUpdateInterval > 0))
                {
                    if (value > 0)
                    {
                        if (this.timer_LVIAddQueue == null)
                        {
                            this.timer_LVIAddQueue = new System.Windows.Forms.Timer();
                            this.timer_LVIAddQueue.Interval = value;
                            this.timer_LVIAddQueue.Tick += new EventHandler(this.timerLVIAddQueue_Tick);
                            this.qLVIsToAdd = new List<ListViewItem>();
                        }
                    }
                    else
                    {
                        this.FlushUpdates();
                    }
                }
                this._uiAsyncUpdateInterval = value;
                if (value > 0)
                {
                    this.timer_LVIAddQueue.Interval = value;
                }
            }
        }
    }
}

